-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented subdivisions for US & DE #16
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work!
however, I am concern about the increase of compile time. Is it possible to have only region-specific public holidays in the source code (e.g. us_ca.rs), and merge them (e.g. us + us_ca) at runtime? 🤔
src/data/helper.rs
Outdated
return; | ||
} | ||
|
||
let m = national_holidays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it is possible to have a national and a subdivision holiday on the same day, but they could be merged into one with this code instead:
let mut m = national_holidays.remove(&year).unwrap_or_default();
for (date, name) in subdivision_holidays {
let national_holiday_name = m.remove(&date).map(|h| h.name + ", ").unwrap_or_default();
m.insert(
date,
Holiday::new(country, national_holiday_name + county_name, date, name),
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this approach is still using big memory size.
Your approach is merge national holiday + subidivsion holiday at "build" time. My suggestion is to do the merge at runtime, i.e. "get", "iter" or "contains". Could you consider this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took so long. Let me know if you are happy with my implementation
I wasn't sure how to implement this at first, but the code works out pretty well. |
src/data/helper.rs
Outdated
return; | ||
} | ||
|
||
let m = national_holidays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this approach is still using big memory size.
Your approach is merge national holiday + subidivsion holiday at "build" time. My suggestion is to do the merge at runtime, i.e. "get", "iter" or "contains". Could you consider this approach?
|
||
let mut national_holidays = de::build(years)?; | ||
|
||
build_year(years, 2000, [], &mut map, COUNTY_CODE, COUNTY_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because of no regional public holidays in the year 2000?
pub fn build(years: Option<&std::ops::Range<Year>>) -> Result<HolidayPerYearMap> { | ||
let mut map = HashMap::new(); | ||
|
||
let mut national_holidays = de::build(years)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this used?
); | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test case where hholidays retrieved from subdivision contains all national holidays?
#9
I implemented subdivisions as their own '
Country
' value.Currently I only implemented the subdivisions for US and DE.
I also refactored the code a bit in the process.
I used this command to generate the code:
python3 gen.py; rustfmt src/**/*.rs
TODO